package com.tid.hbasees;


import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Properties;

@Component
public class SysConfig {

    public static int DEFAULT_CONSUMER_NUM = 1;

    @Resource(name = "props")
    private Properties props;

    public String getHBaseZks() {
        return props.getProperty("hbase.zk");
    }

    public String[] getKafkaTopics() {
        String topicsConfig = props.getProperty("kafka.topics");
        if (topicsConfig == null || topicsConfig.equals("")) {
            return StringUtils.split(topicsConfig, ",");
        }
        return new String[0];
    }

    public String getKafkaZks() {
        return props.getProperty("kafka.zk");
    }

    public int getKafkaConsumerCount() {
        String countConfig = props.getProperty("kafka.consumer.num");
        if (countConfig == null || !StringUtils.isNumeric(countConfig)) {
            return DEFAULT_CONSUMER_NUM;
        } else {
            return Integer.parseInt(countConfig);
        }

    }
}
